home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir31 / in_out.zip / FONETONE.ASM next >
Assembly Source File  |  1993-01-16  |  5KB  |  114 lines

  1. ;=============================================================================
  2. ;Example:
  3. ;       TASM FONETONE.ASM
  4. ;       TLINK/T FONETONE.OBJ 
  5. ;
  6. ;If you are using the A86 assembler - 
  7. ;place a "x" between bit 0 and the letter "B"
  8. ;in each of the binary numbers below.
  9. ;
  10. ;Example: 00000011xB 
  11. ;
  12. ;==============================================================================
  13. ;
  14. code_seg                SEGMENT
  15. ASSUME          cs:code_seg, ds:code_seg, es:code_seg, ss:code_seg
  16. ORG             100h
  17. begin:
  18.         jmp     start
  19. ;----------------------------------
  20. ;William Cravener                    ;Author
  21. ;520 North Stateline Rd
  22. ;Sharon, Pa 16146
  23. ;----------------------------------
  24. delay                   DW      0 
  25. message1                DB      'Press Esc to Quit', 0dh, 0ah, '$' 
  26. message2                DB      'Press any other key to play$'
  27. ;----------------------------------
  28. start                   PROC    NEAR
  29.         mov     ah, 9                   ; DOS function number to print string
  30.         mov     dx, OFFSET message1     ; the message
  31.         int     21h                     ; DOS interrupt
  32.         mov     ah, 9                   ; DOS function number to print string
  33.         mov     dx, OFFSET message2     ; the message
  34.         int     21h                     ; DOS interrupt
  35. again:
  36.         mov     ah, 0                   ; BIOS function wait for key press
  37.         int     16h                     ; BIOS interrupt
  38.         cmp     ah, 1                   ; Esc scan code 
  39.         jz      done                    ; do we stop ?
  40.         call    phone_tone              ; no call phone_tone
  41.         jmp     again                   ; go see if we do it again
  42. done:  
  43.         mov     ax, 4c00h               ; no exit back to DOS
  44.         int     21h                     ; DOS interrupt
  45. start                   ENDP
  46. ;----------------------------------
  47. phone_tone              PROC    NEAR
  48.         cli                             ; disables any keyboard or other
  49.                                         ; possible hardware interference 
  50. go_2: 
  51.         mov     si, 2                   ; do the two six pulse groups, twice
  52. mainx:
  53.         mov     di, 2                   ; do group of six pulses two times
  54. mainy:  
  55.         mov     dx, 6                   ; do six pulses of each tone
  56. mainz: 
  57.         mov     bx, 2000                ; frequency of first tone
  58.         call    in_out_2_port           ; set timer chip and send (bx) to port
  59.         mov     delay, 1                ; place first delay count in delay     
  60.         call    delayer                 ; wait a bit before next tone
  61.         mov     bx, 1600                ; frequency of second tone
  62.         call    in_out_2_port           ; set timer chip and send (bx) to port
  63.         mov     delay, 1                ; place first delay count in delay
  64.         call    delayer                 ; wait a bit before next time
  65.         dec     dx                      ; decrement pulse count
  66.         jnz     mainz                   ; have we done six pulses ?
  67.         dec     di                      ; yes go do second group of six pulses
  68.         jnz     mainy                   ; have we done two groups ?
  69.         in      al, 61h                 ; yes turn speaker off  
  70.         and     al, 11111100b           ; this number turns speaker off
  71.         out     61h, al                 ; send it to port
  72.         mov     delay, 20               ; place second delay count in delay
  73.         call    delayer                 ; wait a while  
  74.         dec     si                      ; if si not 0 go do -
  75.         jnz     mainx                   ; two more six pulse groups
  76.         sti                             ; time to enable interrupts
  77.         ret                             ; go see if user wants to go again
  78. phone_tone              ENDP
  79. ;----------------------------------
  80. delayer                 PROC    NEAR
  81.         push    ax                      ; save these registers
  82.         push    bx
  83.         push    dx
  84.         mov     ah, 0                   ; want to read time
  85.         int     01ah                    ; get initial tick count
  86.         add     dx, delay               ; add our count to tick count  
  87.         mov     bx, dx                  ; place it in bx            
  88. delay_it:                  
  89.         int     01ah                    ; get reading again
  90.         cmp     dl, bl                  ; compare reading to delay count
  91.         jne     delay_it                ; go back and repeat if not equal
  92.         pop     dx
  93.         pop     bx
  94.         pop     ax                      ; restore used registers
  95.         ret
  96. delayer                 ENDP
  97. ;--------------------------------------
  98. in_out_2_port           PROC    NEAR
  99.         mov     al, 10110110b           ; channel 2
  100.         out     43h, al                 ; operation mode 3
  101.         mov     ax, bx                  ; place freqrency in ax
  102.         out     42h, al                 ; send LSB first
  103.         mov     al, ah                  ; place MSB in al
  104.         out     42h, al                 ; send it next
  105.         in      al, 61h                 ; get 8255 port contents
  106.         or      al, 00000011b           ; this number turns speaker on
  107.         out     61h, al                 ; turn it on now
  108.         ret
  109. in_out_2_port           ENDP
  110. ;----------------------------------
  111. code_seg                ENDS
  112.  
  113. END             begin
  114.